package ui.panel.warriorLevelups
{

	import beans.WarriorBean;

	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.geom.Rectangle;

	import globals.ButtonType;
	import globals.Global;

	import ui.component.Button;
	import ui.component.GameTextField;
	import ui.component.Label;
	import ui.component.Page;
	import ui.component.ScaleBitmap;
	import ui.component.TextButton;
	import ui.face.Bar;

	import util.TextStyle;
	import util.UIUtil;

	/**
	 * 英雄晋级的当前英雄信息
	 * @author luguobin
	 */
	public class WarriorNowInfo extends Sprite
	{
		private var _hero:Bitmap;
		private var _nameLabel:GameTextField;
		private var _jobLabel:GameTextField;
		private var _expBar:Bar; //经验
		private var _txtItems:Vector.<GameTextField> = new Vector.<GameTextField>;

		private var warriorBean:WarriorBean;

		public function WarriorNowInfo()
		{
			super();

			var bg:ScaleBitmap = new ScaleBitmap(Global.assetsManager.getAssetsAsBitmapData("tower_bg"));
			bg.scale9Grid = new Rectangle(35, 35, 14, 14);
			bg.width = 150;
			bg.height = 335;
			this.addChild(bg);

			_hero = new Bitmap();
			_hero.y = 15;
			this.addChild(_hero);

			_nameLabel = new GameTextField();
			_nameLabel.defaultTextFormat = TextStyle.getTextFormat(0xFFFFFF, 12, true, "center");
			_nameLabel.width = bg.width;
			_nameLabel.y = 115;
			this.addChild(_nameLabel);
			_jobLabel = new GameTextField();
			_jobLabel.defaultTextFormat = TextStyle.getTextFormat(0xFFFFFF, 12, false, "center");
			_jobLabel.width = bg.width;
			_jobLabel.y = 135;
			this.addChild(_jobLabel);

			_expBar = new Bar("experience_front", "experience_bg", true);
			_expBar.x = 16;
			_expBar.y = 160;
			this.addChild(_expBar);

			var txtX:Array = [45, 80, 45, 80, 45, 80];
			var txtY:Array = [185, 185, 205, 205, 225, 225];

			for(var i:int = 0; i < 6; i++)
			{
				var txt:GameTextField = new GameTextField();
				txt.defaultTextFormat = TextStyle.getTextFormat();
				txt.x = txtX[i];
				txt.y = txtY[i];
				this.addChild(txt);
				_txtItems.push(txt);
			}
			TextStyle.addTextFrame(_txtItems[1], 0x653011);
			TextStyle.addTextFrame(_txtItems[3], 0x653011);
			TextStyle.addTextFrame(_txtItems[5], 0x653011);

			var bean:WarriorBean = new WarriorBean();
			bean.name = "阿波罗";
			bean.job = "太阳神";
			bean.image = "avatar_1_1";
			bean.level = 10;
			bean.exp = 20;
			bean.power = 300;
			bean.magic = 400;
			//TODO：测试
			update(bean);
		}

		public function update(bean:WarriorBean):void
		{
			warriorBean = bean;

			_hero.bitmapData = Global.assetsManager.getAssetsAsBitmapData("avatar_1_1", "warrior");
			_hero.x = (this.width - _hero.width) * 0.5;
			_nameLabel.text = "英雄名字";
			_jobLabel.text = "弓箭手 lv.2";
			_expBar.update(30, 100);

			(_txtItems[0] as GameTextField).mytext = "武力:";
			(_txtItems[1] as GameTextField).mytext = "100";
			(_txtItems[2] as GameTextField).mytext = "魔力:";
			(_txtItems[3] as GameTextField).mytext = "123";
			(_txtItems[4] as GameTextField).mytext = "内政:";
			(_txtItems[5] as GameTextField).mytext = "145";
		}

		public function clear():void
		{
			warriorBean = null;
			_nameLabel.text = _jobLabel.text = "";
			_hero.bitmapData = null;
			_expBar.clear();
		}
	}
}